package com.bi.autotest.cases;

import com.auto.base.Assertion;
import com.auto.base.InitAppium;
import com.bi.autotest.operations.H5LoginOperation;
import com.bi.autotest.operations.MyLoginOperation;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;

/**
 * Created by yidian on 2018/4/13.
 */
public class H5Login extends InitAppium {

    private MyLoginOperation myLoginOperate;
    private H5LoginOperation h5LoginOperation;

    @BeforeClass
    public void initDriver(){
        try {
            setUp();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(driver);
        myLoginOperate = new MyLoginOperation(driver);
        h5LoginOperation=new H5LoginOperation(driver);
    }

    @Test(priority = 0)
    public void login_HasCache(){
        boolean isSuccess=myLoginOperate.LoginPreNew();
        Assertion.verifyEquals(isSuccess,true,"直接用缓存登陆的情况 开通了渠道");
    }
    @Test(priority = 1)
    public void changeFlavor(){
        boolean isSuccess=h5LoginOperation.isChangeFlavorSuccess();
        Assertion.verifyEquals(isSuccess,true,"直接用缓存登陆的情况 未开通渠道");
    }

    @Test(priority = 2)
    public void changeUser_phoneError(){
        h5LoginOperation.QWERChangeUser();
        myLoginOperate.login("152105","999999");
        boolean isHasPhoneError=h5LoginOperation.isHasPhoneError();
        Assertion.verifyEquals(isHasPhoneError,true,"切换用户时，手机号输入错误的情况");
    }

    @Test(priority = 3)
    public void changeUser_noPhone(){
        h5LoginOperation.clickConfirmButton();
        myLoginOperate.clearText();
        myLoginOperate.login("","999999");
        boolean isHasNoPhone=h5LoginOperation.isHasNoPhone();
        Assertion.verifyEquals(isHasNoPhone,true,"切换用户时，不输入手机号的情况");
    }

    @Test(priority = 4)
    public void changeUser_noVertifyCode(){
        h5LoginOperation.clickConfirmButton();
        myLoginOperate.clearText();
        myLoginOperate.login("18435790396","");
        boolean isHasNoVCode=h5LoginOperation.isHasNoVCode();
        Assertion.verifyEquals(isHasNoVCode,true,"切换用户时，不输入验证码的情况");
    }

    @Test(priority = 5)
    public void changeUser_errorVertifyCode(){
        h5LoginOperation.clickConfirmButton();
        myLoginOperate.clearText();
        myLoginOperate.login("18435790396","123456");
        boolean isHasErrorVCode=h5LoginOperation.isHasErrorVCode();
        Assertion.verifyEquals(isHasErrorVCode,true,"切换用户时，输入错误验证码的情况");
    }

    @Test(priority = 6)
    public void changeUser_phoneCorrect_noRegist(){
        h5LoginOperation.clickConfirmButton();
        myLoginOperate.clearText();
        myLoginOperate.login("15210523099","999999");
        boolean isHasPhoneError=h5LoginOperation.isHasNoOpenStore();
        Assertion.verifyEquals(isHasPhoneError,true,"切换用户时，输入未注册的手机号的情况");
    }

    @Test(priority = 7)
    public void changeUser_phoneCorrect(){
        h5LoginOperation.clickLoginButton_noRegist();
        myLoginOperate.clearText();
        boolean isLoginSucess=myLoginOperate.login("15210523096","999999");
        Assertion.verifyEquals(isLoginSucess,true,"切换用户时，输入已注册开店的手机号正确的情况");

        //最后一步将店铺切换到开通渠道的店
        myLoginOperate.selectGG();

    }



}
